
#ifndef CONNECTOR_H_
#define CONNECTOR_H_

#ifdef __cplusplus
extern "C" {
#endif

#include "callback.h"

#define IPADDR_LEN		128

struct core;
struct connector;
struct session;
struct aeEventLoop;

#define CONNECTING_STAT		0
#define CONNECTED_STAT		1
#define DISCONNECT_STAT		2

typedef struct connector {
	int id;
	char* serverAddr;
	int serverPort;
	int stat;

	struct session* session;
	struct aeEventLoop* eventLoop;
	IServerCallBack* callBackHandle;
} connector;

struct connector* initConnector(char* serverAddr, int serverPort);
void destroyConnector(struct connector* con);

int startBlockConnect(struct connector* con, struct core* c);
int startNonBlockConnect(struct connector* con, struct core* c);
int reConnectConnector(struct core* c, struct session* session);
void stopConnect(struct connector* con);


void sendConnect(struct connector* con, char* sendBuf, int sendBufLen);

#ifdef __cplusplus
}
#endif

#endif /* CONNECTOR_H_ */
